#include <stdio.h>
#include <unistd.h>
#include <errno.h>
#include <string.h>

int main (int argc, char **argv)
{
	FILE *fp = NULL;
	char c = 0;
	
	if (argc < 2) {
		return -1;
	}
	//打开文件, 返回文件流
	fp = fopen (argv[1], "r");
	if (NULL == fp) {
		//printf ("file %s fopen failed! errno: %d \n", argv[1], errno);
		printf ("%s\n", strerror(errno));
		return -1;
	}
	printf ("file %s fopen successed! errno: %d \n", argv[1], errno);
	//printf ("file %s fopen successed!\n", argv[1]);
	while (1) {
		//第一次读取一个字符, 读完之后, 文件流会自动向后偏移
		c = fgetc (fp);
		if (EOF == c) {
			//如果发生错误
			if (ferror(fp)) {
				fprintf (stderr, "fgetc () error!\n");
				fclose (fp);
			}
			break;
		}

		fputc (c, stdout);
		//fflush (NULL); //刷新所有的输出流
		sleep (1);
	}
	fclose (fp);
	return 0;
}
